from threading import Thread

my_sum = 0


def sum_func(start, end):
    global my_sum
    for i in range(start, end):
        my_sum += i


def run_thread():
    t1 = Thread(target=sum_func, args=(1, 5000000))
    t2 = Thread(target=sum_func, args=(5000000, 10000000))
    # 产生资源竞争
    # 加法运算的底层：
    #        1.取出my_sum值  -->  2.my_sum加一运算  -->  3.新值写回my_sum内存
    #        my_sum 100    100 | 100   102/ 104
    t1.start()
    t2.start()
    t1.join()
    t2.join()
    print(my_sum)


if __name__ == "__main__":
    run_thread()
